package org.dht.com.tra.nw;

import org.apache.log4j.Logger;
import org.dht.com.tra.Communicator;

/**
 * The <code>CommunicationManagerTCP</code> class is an
 * <code>CommunicationManagerNetworkLAN</code>. Implemented the creation of
 * transfer object and unicast manager. Required params: PORT_TCP_RESOURCE and
 * PORT_TCP
 * 
 */
public class CommunicationManagerTCP extends CommunicationManagerNetworkLAN {

	/**
	 * The <code>CommunicationManagerTCPProperties</code> enum contains params
	 * required for communication
	 * 
	 * @author dpelaez
	 * 
	 */
	public enum CommunicationManagerTCPProperties {
		PORT_TCP_RESOURCE, PORT_TCP
	}

	/**
	 * Logger
	 */
	private static final Logger logger = Logger
			.getLogger(CommunicationManagerTCP.class);

	/**
	 * Creates a BytesTransferManagerTCP instance. Required param in
	 * CommunicationProperties called PORT_TCP_RESOURCE
	 */
	protected Communicator createUnicastBigManager() {
		int portTcp;
		if (communicationProperties
				.containsKey(CommunicationManagerTCPProperties.PORT_TCP_RESOURCE
						.name())) {
			portTcp = Integer.parseInt(communicationProperties
					.get(CommunicationManagerTCPProperties.PORT_TCP_RESOURCE
							.name()));
		} else {
			IllegalArgumentException illegalArgumentException = new IllegalArgumentException(
					"Property PORT_TCP_RESOURCE not found");

			logger.error("Property PORT_TCP_RESOURCE not found",
					illegalArgumentException);

			throw illegalArgumentException;
		}
		unicastBigManager = new UnicastBigManagerTCP(portTcp);

		return unicastBigManager;
	}

	/**
	 * Creates a UnicastManagerTCP instance. Required param in
	 * CommunicationProperties called PORT_TCP.
	 */
	protected Communicator createUnicastManager() {
		int portTcp;
		if (communicationProperties
				.containsKey(CommunicationManagerTCPProperties.PORT_TCP.name())) {
			portTcp = Integer.parseInt(communicationProperties
					.get(CommunicationManagerTCPProperties.PORT_TCP.name()));
		} else {
			IllegalArgumentException illegalArgumentException = new IllegalArgumentException(
					"Property PORT_TCP not found");

			logger.error("Property PORT_TCP not found",
					illegalArgumentException);

			throw illegalArgumentException;
		}
		unicastManager = new UnicastManagerTCP(portTcp);

		return unicastManager;
	}

}
